//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using CommunityServer.Components;

namespace CommunityServer.Galleries.Components
{
	/// <summary>
	/// Base class for all Weblog Syndication feeds
	/// </summary>
	public abstract class BaseGallerySyndicationHandler : BaseSyndicationHandler
	{
		public BaseGallerySyndicationHandler()
		{
		}

		private GalleryConfiguration _galleryConfig;
		protected GalleryConfiguration GalleryConfig
		{
			get
			{
				if (_galleryConfig == null)
					_galleryConfig = GalleryConfiguration.Instance();

				return _galleryConfig;
			}
		}

		/// <summary>
		/// The length of time the feed should be cached in seconds.
		/// </summary>
		protected override int CacheTime
		{
			get
			{
				return CSCache.SecondFactorCalculate(GalleryConfig.RssCacheWindowInSeconds);
			}
		}
		
		/// <summary>
		/// Appends http://Host:Port to all blog urls
		/// </summary>
		protected override string BaseUrl
		{
			get
			{
				return Globals.HostPath(Context.Request.Url);
			}
		}


        private Gallery gallery = null;
		protected override Section GetCurrentSection
		{
			get
			{
				CSContext cSContext = CSContext.Current;
                if(gallery == null && cSContext.ApplicationKey != null)
                {
                    gallery =  Galleries.GetGallery(cSContext.ApplicationKey);
                    Permissions.AccessCheck(gallery,Permission.View,cSContext.User);
                }

                return gallery;
			}
		}

		protected Gallery CurrentGallery
		{
			get{ return CurrentSection as Gallery;}
		}


	}
}
